﻿using AutoMapper;
using B.S.Data.MES.API.Applications.approve.Command;
using B.S.Domain.Node;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.approve.CommandHandlers
{
    public class AddShenPiCommandHandlers : IRequestHandler<AddShenPiCommand, APIRequst<int>>
    {
        private readonly IBaseRepository<ShenPiinfo> shePiRepository;
        private readonly IMapper mapper;

        public AddShenPiCommandHandlers(IBaseRepository<Settinginfo> settinginfoRepository, IBaseRepository<ShenPiinfo> ShePiRepository, IMapper mapper)
        {
            SettinginfoRepository = settinginfoRepository;
            shePiRepository = ShePiRepository;
            this.mapper = mapper;
        }

        public IBaseRepository<Settinginfo> SettinginfoRepository { get; }
        /// <summary>
        /// 审批
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<APIRequst<int>> Handle(AddShenPiCommand request, CancellationToken cancellationToken)
        {
           ShenPiinfo Shen = new ShenPiinfo();
            Shen.ShenQiId = request.PersonId;
            Shen.ShenQiName = request.PersonName;
            Shen.PersonId = request.PersonId;
            Shen.PersonName = request.PersonName;
            var Setting = SettinginfoRepository.GetAll().ToList();
            Shen.CurrNodeNo = Setting[0].NodeNo;
            Shen.CurrNodeName = Setting[0].NodeName;
            Shen.NodeNextNo = Setting[1].NodeNo;
            Shen.NodeNextName = Setting[1].NodeName;
            Shen.NetxPersonId = Setting[1].UserId;
            Shen.NetxPersonName = Setting[1].UserNickName;
            Shen.State = "已提交";
            Shen.Yjian="";
            await shePiRepository.Add(Shen);
            return new APIRequst<int>
            {
                Code = RequstCode.成功,
                Msg = RequstCode.成功.ToString()
            };
            
            

            


        }
       
    }
}
